package com.mq.rabbitmq.topic.demo2;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;

/**
 * Created by Administrator on 2017/8/11.
 */
public class HelloReceive2 {

//    @Bean("demoContainerFactory")
//    public SimpleRabbitListenerContainerFactory pointTaskContainerFactor() {
//        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
//        factory.setPrefetchCount(1);//每个消费者获取最大投递数量 默认50
//        factory.setConcurrentConsumers(100);//消费者数量，默认10
//        return factory;
//    }

    @Bean("demoContainerFactory")
    public SimpleRabbitListenerContainerFactory myContainerFactory(
            SimpleRabbitListenerContainerFactoryConfigurer configurer,
            ConnectionFactory connectionFactory) {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setPrefetchCount(100);
        factory.setConcurrentConsumers(100);//消费者数量，默认10
        configurer.configure(factory, connectionFactory);
        return factory;
    }

    //message消息队列不存在就会报错，测试
    //为什么messages不会监听到message消息
    //3 一个jvm只能消费一次吗？
    @RabbitListener(queues= ATopicRabbitConfig.messages,containerFactory="demoContainerFactory")    //监听器监听指定的Queue
    public void processC(String str) {
        System.out.println("HelloReceive2<<<<<<<<<<<<<<<<<<<:"+str +",currentName:"+Thread.currentThread().getName());
    }
}
